<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Document</title>
	</head>
	<body>
		<button onclick="start()">开启全局定时器</button>
		<button onclick="stopAll()">停止全局定时器</button>

		<button onclick="destory()">销毁全局定时器</button>
		<button onclick="remove(1)">移除指定id1定时器</button>
		<button onclick="remove(2)">移除指定id2定时器</button>
		<button onclick="remove(3)">移除指定id3定时器</button>
		
		<script type="module">
			import Timer from './timer.js'
			// Time.delay = 4
			// console.log(Time.delay);
			let tid1 = Time.loop(function() {
				console.log('time1')
				console.log(Time.time());
			}, 500)
			let tid2 = Time.loop(function() {
				console.log('time2')
			}, 1000)
			let tid3 = Time.loop(function() {
				console.log('time3')
			}, 3500)
			// Time.once(function(){
			//     console.log('time4');
			// }, 4000)
			function start() {
				Time.init()
			}

			function remove(idInd) {
				switch (idInd) {
					case 1:
						Time.remove(tid1)
						break
					case 2:
						Time.remove(tid2)
						break
					case 3:
						Time.remove(tid3)
						break
					default:
						break
				}
			}

			function stopAll() {
				Time.stopAll()

			}

			function destory() {
				Time.destory()
			}

			let str =
				`{"a":5,"sdhfdgghfs":"sd森岛帆高会受到法国~！@#￥%……&（）——+{}|A:\"<>?123-=/*-+,./';'\"","llwerweewl":"四大金刚豆腐脑姑获鸟讽德诵功地开发搜集个IE让他你刚发生沃尔夫及偶尔玩if人家嘛少嘚瑟地方IE我扫地佛金额哇哦i荣放那我就KRNWEOITGJREIGNIOASEGIOERITHOIASDASEDJFTIOEW设个IE认识大概·12~！@#￥%……&*（）————+{}|：“；‘《》？，。、佛教个","sdhfdghfs":"sd森岛帆高会受到法国~！@#￥%……&（）——+{}|A:\"<>?123-=/*-+,./';'\"","llwerewl":"四大金刚豆腐脑姑获鸟讽德诵功地开发搜集个IE让他你刚发生沃尔夫及偶尔玩if人家嘛少嘚瑟地方IE我扫地佛金额哇哦i荣放那我就KRNWEOITGJREIGNIOASEGIOERITHOIASDASEDJFTIOEW设个IE认识大概·12~！@#￥%……&*（）————+{}|：“；‘《》？，。、佛教个","sdfs":"sd森岛帆高会受到法国~！@#￥%……&（）——+{}|A:\"<>?123-=/*-+,./';'\"","lll":"四大金刚豆腐脑姑获鸟讽德诵功地开发搜集个IE让他你刚发生沃尔夫及偶尔玩if人家嘛少嘚瑟地方IE我扫地佛金额哇哦i荣放那我就KRNWEOITGJREIGNIOASEGIOERITHOIASDASEDJFTIOEW设个IE认识大概·12~！@#￥%……&*（）————+{}|：“；‘《》？，。、佛教个"}`
			//ArrayBuffer转字符串
				var r = new FileReader();
			function ab2str(u, f) {
				var b = new Blob([u]);
				r.readAsText(b, 'utf-8');
				r.onload = function() { if (f) f.call(null, r.result) }
			}
			//字符串转字符串ArrayBuffer
			function str2ab(s, f) {
				var b = new Blob([s], { type: 'text/plain;charset=utf-8' });
				// var r = new FileReader();
				r.readAsArrayBuffer(b);
				r.onload = function() { if (f) f.call(null, r.result) }
			}
			// 记录备用，网上有用Uint16Array视图转换的并不行，因为utf-8编码字符字节编码长度不一定是两个字节,英文是1字节，中文2-3字节，其他表情符号4字节。
			//实际调用

			str2ab(str, function(arrayBuffer) {
				//ab为ArrayBuffer
				console.log(arrayBuffer);
				ab2str(arrayBuffer, function(str) {
					//str为字符串
					console.log(str);
				});
			});
		</script>
	</body>
</html>
